<?php if ($this->getShowForm()): ?>
    <form id="form_associated_suppliers" name="form_associated_suppliers">
    <?php endif; ?>

    <div id="div_associated_suppliers">

        <script>

            var linkSupplierUrl = '<?php echo $this->getUrl('Purchase/Products/LinkSupplier', array('product_id' => 'XXX', 'supplier_id' => 'YYY')); ?>';
            var refreshSupplierUrl = '<?php echo $this->getUrl('Purchase/Products/AjaxSuppliers', array('product_id' => $this->getProduct()->getId())) ?>';
            var removeSupplierUrl = '<?php echo $this->getUrl('Purchase/Products/DeleteAssociatedSupplier', array('pps_id' => 'XXX')); ?>';
            var loadSupplierUrl = '<?php echo $this->getUrl('Purchase/Products/GetSupplierInformation', array('pps_id' => 'XXX')); ?>';
            var saveSupplierUrl = '<?php echo $this->getUrl('Purchase/Products/SaveAssociatedSupplier'); ?>';

        </script>

        <div class="entry-edit">

            <div class="grid">
                <table cellspacing="0" class="data" width="100%">
                    <thead>
                        <tr class="headings">
                            <th><?php echo $this->__('Name') ?></th>
                            <th class="a-center">Date</th>
                            <th class="a-center"><?php echo $this->__('Last Unit Price') ?></th>
                            <th class="a-center"><?php echo $this->__('Last Price + cost') ?></th>
                            <th class="a-center"><?php echo $this->__('Stock') ?></th>
                            <th class="a-center"><?php echo $this->__('Ref') ?></th>
                            <th class="a-center"><?php echo $this->__('Action') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $Suppliers = $this->getSuppliers();
                        foreach ($Suppliers as $Supplier) {
                            echo '<tr>';
                            echo '<td><a href="' . $this->getUrl('Purchase/Suppliers/Edit') . 'sup_id/' . $Supplier->getpps_supplier_num() . '">' . $Supplier->getsup_name() . '</a></td>';
                            echo '<td class="a-center">' . $Supplier->getpps_last_order_date() . '&nbsp;</td>';
                            echo '<td class="a-center">';
                            if ($Supplier->getpps_last_unit_price() > 0)
                                echo $this->getDefaultCurrency()->formatTxt($Supplier->getpps_last_unit_price());
                            echo '&nbsp;</td>';
                            echo '<td class="a-center">';
                            if ($Supplier->getpps_last_price() > 0)
                                echo $this->getDefaultCurrency()->formatTxt($Supplier->getpps_last_price());
                            echo '&nbsp;</td>';

                            echo '<td class="a-center">';
                            if ($Supplier->getpps_quantity_product() != null)
                                echo $Supplier->getpps_quantity_product();
                            echo '&nbsp;</td>';

                            echo '<td class="a-center">' . $Supplier->getpps_reference() . '&nbsp;</td>';
                            echo '<td class="a-center"><a  href="javascript:loadSupplier(' . $Supplier->getpps_num() . ');">' . $this->__('Edit') . '</a> - <a href="javascript:removeSupplier(' . $Supplier->getpps_num() . ');">' . $this->__('Delete') . '</a></td>';
                            echo '</tr>';
                        }
                        ?>
                    </tbody>
                    <thead>
                        <tr class="headings">
                            <th class="a-center" colspan="7>"><?php echo $this->__('Add Supplier') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="a-center" colspan="7"><?php echo $this->getNonLinkedSuppliersAsCombo(); ?> <input type="button" value="<?php echo $this->__('Add') ?>" onclick="linkSupplier();"></td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div id="div_supplier_edit" style="display: none">

                <div class="entry-edit-head">
                    <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Edit supplier / product association'); ?></h4>
                </div>

                <fieldset>
                    <input type="hidden" id="pps_num" name="pps_num" value="">
                    <table border="0" width="100%">
                        <tr>
                            <td><?php echo $this->__('Supplier') ?></td>
                            <td><span id="sup_name"></span></td>
                        </tr>
                        <tr>
                            <td><?php echo $this->__('Supplier Reference') ?></td>
                            <td><input type="text" id="pps_reference" name="pps_reference"></td>
                        </tr>
                        <tr>
                            <td><?php echo $this->__('Price Position') ?></td>
                            <td><?php echo $this->getPricePositionAsCombo('pps_price_position'); ?></td>
                        </tr>
                        <tr>
                            <td><?php echo $this->__('Last Unit Price') ?></td>
                            <td><input type="text" id="pps_last_unit_price" name="pps_last_unit_price" size="6"></td>
                        </tr>
                        <tr>
                            <td><?php echo $this->__('Last Price + cost') ?></td>
                            <td><input type="text" id="pps_last_price" name="pps_last_price" size="6"></td>
                        </tr>
                        <tr>
                            <td><?php echo $this->__('Stock level') ?></td>
                            <td><input type="text" id="pps_quantity_product" name="pps_quantity_product" size="4"></td>
                        </tr>
                        <tr>
                            <td><?php echo $this->__('Comments') ?></td>
                            <td><textarea id="pps_comments" name="pps_comments" cols="50" rows="3"></textarea></td>
                        </tr>
                        <tr>
                            <td><?php echo $this->__('Save') ?></td>
                            <td><input type="button" value="<?php echo $this->__('Save') ?>" onclick="SaveAssociatedSupplier()"></td>
                        </tr>
                    </table>
                </fieldset>
            </div>


        </div>

    </div>

    <?php if ($this->getShowForm()): ?>
                        </form>
<?php endif; ?>

